!> IO : input/output subroutines
!! This module contains input/output subroutines for LACM
!! @author Dharhas Pothina
!! @created 20080208
!! @modified 20080421
!! @file lacm_io.f90
module lacm_io
	use lacm_globals
	implicit none
contains
	!> read_iodef : Reads io directories and filenames
	!! from command line or from iodef.in
	!! iodef.in :
	!! indir !input directory
	!! outdir !output directory
	!! prefix !filename prefix
	!! @author Dharhas Pothina
	subroutine read_iodef(fname)
		character (len=longtext) :: fname
		!open(unit=10,file=fname,action='read')
		!read(10,*)
		!! @todo Add ability of command line/iodef.in use to specify input files
		indir="input"
		outdir="outputs"
		prefix="test"
		meshfile=trim(indir)//'/'//trim(prefix)//'_mesh.in'
		paramfile=trim(indir)//'/'//trim(prefix)//'param.in'
		write(*,*) 'io file definitions read successfully'
	end subroutine read_iodef

	!> read_mesh : Reads mesh file named in iodef.in
	!! Text !Mesh Description
	!! nv !Number of sigma levels
	!! np !Number of nodes
	!! x y zbottom ztop
	!! @author Dharhas Pothina
	subroutine read_mesh(fname)
		character (len=longtext) :: fname
		integer ii,node
!		write(*,*) trim(fname)
		open(unit=10,file=trim(fname),action='read')
		read(10,*) meshdescription
		read(10,*) nv
		read(10,*) np

		allocate(x(np))
		allocate(y(np))
		allocate(ztop(np))
		allocate(zbottom(np))

		do ii=1,np
			read(10,*) node,x(ii),y(ii),ztop(ii),zbot(ii)
			write(*,*) node,x(ii),y(ii),ztop(ii),zbot(ii)
		end do !ii
		write(*,*) 'mesh read successfully'
	end subroutine read_mesh

	!> read_iodef : Reads runtime parameters from file specified in iodef.in
	!! Parameters are specified as keyword:value pairs
	!! @author Dharhas Pothina
	subroutine read_params
		write(*,*) 'read_params'
	end subroutine read_params

end module lacm_io
